package graphics.screens;

import graphics.BootColor;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import state.State;
import tool.ImageUtils;
import tool.KeyCode;
import boot.Boot;

public class PopUpPlaylistModeScreen extends Canvas implements CommandListener {

	private final Command okCommand = new Command("OK", Command.OK, 1);
	private final Command cancelCommand = new Command("Cancel", Command.EXIT, 1);

	public PopUpPlaylistModeScreen() {
		setup();
	}

	public void setup() {
		addCommand(okCommand);
		addCommand(cancelCommand);
		setCommandListener(this);
	}

	protected void paint(Graphics graphics) {
		graphics.setColor(BootColor.BLACK);
		graphics.fillRect(0, 0, 240, 250);

		drawSplash(graphics);

		graphics.setColor(BootColor.FLASHY_MENU_COLOR);
		graphics.drawString("Enable", 120, (graphics.getFont().getHeight()),
				Graphics.TOP | Graphics.HCENTER);
		graphics.drawString("playlist mode ?", 120, (graphics.getFont()
				.getHeight() * 2), Graphics.TOP | Graphics.HCENTER);
	}

	private void drawSplash(Graphics graphics) {
		Image splash = ImageUtils.getImageFromImageFolder("/Musique-mini.png");
		graphics.drawImage(splash, 0, 0, Graphics.LEFT | Graphics.TOP);
	}

	public void commandAction(Command command, Displayable disp) {

		if (command == okCommand) {
			Boot.addState(State.PLAYLIST_MODE);
			Boot.createNewSuggestScreen();
			Boot.getInstance().readyToGo();
		} else if (command == cancelCommand) {
			Boot.removeState(State.PLAYLIST_MODE);
			Boot.createNewSuggestScreen();
			Boot.getInstance().readyToGo();
		}
	}

	public void keyPressed(int keyCode) {

		if (keyCode == KeyCode.FIVE) {
			Boot.addState(State.PLAYLIST_MODE);
			Boot.wickedKeyPressed();
			Boot.getInstance().readyToGo();
		} else if (keyCode == KeyCode.SIX) {
			Boot.removeState(State.PLAYLIST_MODE);
			Boot.wickedKeyPressed();
			Boot.getInstance().readyToGo();
		}
	}
}
